<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>How the Library Works</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('frames.html', 'topic', '00701.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element94">
<a href="01259.html" target="topic">System Service Libraries Help</a> &gt; <a href="00704.html" target="topic">Console System Service Library Help</a> &gt; <a href="00708.html" target="topic">Using the Library</a> &gt; <a href="00701.html" target="topic">How the Library Works</a></div>
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element1">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element2">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element90">
<a href="00697.html" target="topic">Previous</a> | <a href="00708.html" target="topic">Up</a> | <a href="00699.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element96">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: SYS CONSOLE How the Library Works Topic Title: How the Library Works)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table><div class="Element5">
How the Library Works</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<a name="PageContent"></a><div class="Element58">
<a name="4465736372697074696F6E"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
Each supported console device has its own implementation of the Console System service APIs. Function pointers to the console device implementations are provided in the console device descriptor registered to each console instance. This allows the user to utilize the same API for all console devices, making application code more portable across different devices.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
<strong>Note</strong>: Currently UART and USB CDC Console Devices are supported.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
<strong>Read</strong>&nbsp;</p>
<p class="Element10">
The console device layer saves the received data in an internal receive ring buffer. The size of the receive buffer is user configurable. When the application submits a read request, the console device layer copies the available data from the receive buffer to the application buffer and returns the number of bytes copied. The application must check the return value to verify the number of bytes copied. If the return value is less than the one requested, the application should retry again after some time. Additional APIs let application query the number of bytes available in the receive buffer and the free space in the receive buffer. It is the application's responsibility to ensure it reads the data out from the receive buffer at regular intervals to avoid receive buffer overflow and hence loss of data.&nbsp;</p>
<p class="Element10">
<strong>Write</strong>&nbsp;</p>
<p class="Element10">
For the write requests, the console device layer copies the application data into the transmit ring buffer. The size of the transmit buffer is user configurable. The number of bytes actually copied in the transmit buffer is indicated by the return value of the write API. Depending on the free space available in the transmit buffer; the application data may be completely or partially copied. It is the application's responsibility to check the return value. If the return value is less than the one requested, the application should retry sending the remaining characters after some time. Additional APIs, let application query the free space available in the transmit buffer. APIs are provided to query the number of bytes pending transmission and the configured size of the transmit buffer.&nbsp;</p>
<p class="Element10">
<strong>State Machine</strong>&nbsp;</p>
<p class="Element10">
For UART the read and write state machines are run from the interrupt context in both bare-metal and RTOS environment. For USB CDC console, the read and write state machine is run from a while(1) loop along with other tasks. In RTOS environment, a separate RTOS thread runs the USB CDC console state machine.</p></div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<div class="Element95">
<a href="01259.html" target="topic">System Service Libraries Help</a> &gt; <a href="00704.html" target="topic">Console System Service Library Help</a> &gt; <a href="00708.html" target="topic">Using the Library</a> &gt; <a href="00701.html" target="topic">How the Library Works</a></div>
<div class="Element93">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element3">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element4">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element91">
<a href="00697.html" target="topic">Previous</a> | <a href="00708.html" target="topic">Up</a> | <a href="00699.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element97">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: SYS CONSOLE How the Library Works Topic Title: How the Library Works)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table></div>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>